Cktalk wall = new Cktalk();
WallMode[] allModes;
WallMode currentMode;
int currentModeStart;
final int DEFAULT_MODE = 0;

void setup()
{
  size(528, 528);
  colorMode(RGB, 255);

  allModes = new WallMode[10];
  allModes[0] = new SlotMachine(3, 10, 16);
  allModes[1] = new CycleThing(this);
  allModes[2] = new Cardioid();
  allModes[3] = new FastFourierTransform48(this);
  allModes[4] = new FastFourierTransform48(this);
  allModes[5] = new FastFourierTransform48(this);
  allModes[6] = new CycleThing(this);
  //one camera
  allModes[7] = new CamFeed(this);
  //automagically the other camera!
  allModes[8] = new CamFeed(this);
  allModes[9] = new CycleThing(this);
  //   allModes[9] = new MoviePlay(this);

  currentMode = allModes[DEFAULT_MODE];
  for (int i = 0; i < allModes.length; i++)
    if (allModes[i] != null)
      allModes[i].setup();

  frameRate(30);
}


void draw() {
  println(currentMode.getNewModeIdentifier());

  if ( currentMode.getNewModeIdentifier() == 4 )
  {
    colorMode(HSB, 255);
    currentMode.draw();
  }
  else {
    colorMode(RGB, 255);
    currentMode.draw();
  }


  wall.display(get(00, 00, 48, 48));
  image(get(00, 00, 48, 48), 48, 48, 480, 480);
  if (currentMode.getDisplayTime() > -1 && 
    (millis() - currentModeStart)/1000 > currentMode.getDisplayTime()) 
    setMode(DEFAULT_MODE);
  // some modes can force changes
  if (currentMode.shouldChangeMode()) {
    setMode(currentMode.getNewModeIdentifier());
  }
}

void keyPressed() {
  if (key >=48 && key <= 57)
    setMode(((int)key)-48);

  currentMode.keyPressed();
}

void setMode(int nextMode) {  
  currentModeStart = millis();
  currentMode = allModes[nextMode];
  currentMode.modeSelected();
}

